<template>
  <div class="risk">
    <div class="add" @click="edit()">添加附件</div>
    <eagle-page-list
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      :url="url"
      :conditions="conditions"
      :pageSize="20"
      :isPage="false"
      :isShowSearch="false"
    >
      <template #list>
        <eagle-cell
          style="margin-top: 10px"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="warn_item">
            <div>
              <eagle-card @click="viewFile(item)">
                <template #thumb>
                  <!-- <img src="baseUrl + item.Attachs" alt=""> -->
                  <eagle-image
                    :src="baseUrl + item.Cover"
                    width="80"
                    height="80"
                  />
                </template>
                <template #title>
                  <!-- <img src="baseUrl + item.Attachs" alt=""> -->
                  <h3>{{ item.CertName }}</h3>
                </template>
                <template #desc>
                  <div>{{ item.ResName }}</div>
                  <div>附件类型：{{ item.EquFileTypeName }}</div>
                  <div>上传时间：{{ item.CreateDate }}</div>
                </template>
              </eagle-card>
            </div>
            <eagle-divider />
            <div class="dep_btm">
              <div class="btm_item" @click="handleDelete(item)">
                <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
                <div class="mr-10">删除该附件</div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </template>
    </eagle-page-list>
    <eagle-dialog
      v-model="show"
      :title="title"
      @confirm="handleConfirm()"
      show-cancel-button
    >
      <eagle-form>
        <eagle-input
          name="CheckDate"
          :value="form.CheckDate"
          label="最近检验日期"
          readonly
          placeholder="请选择"
          islink
          @click="handleShow('CheckDate')"
        ></eagle-input>
        <eagle-input
          name="NextCheckDate"
          :value="form.NextCheckDate"
          label="下次检验日期"
          readonly
          placeholder="请选择"
          islink
          @click="handleShow('NextCheckDate')"
        ></eagle-input>
      </eagle-form>
    </eagle-dialog>
    <eagle-calendar
      color="#1989fa"
      v-model="showCalendar"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import { Dialog } from "vant";
import { formatDate, getDate } from "@/utils/getDate";
export default {
  data() {
    return {
      url: "/EquEquipment/GetEquipmentSafeFileFile",
      conditions: {},
      queryParams: {
        id: this.$route.query.id,
      },
      list: [],
      baseUrl: process.env.VUE_APP_BASE_API,
      showCalendar: false,
      show: false,
      value: "",
      form: {},
      title: "",
    };
  },
  created() {},
  methods: {
    bindData(data) {
      
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    viewFile(item) {
      this.$router.push({
        path: "fileDetail",
        query: { fileFath: item.AttMiddelPath },
      });
      console.log("adadadsda");
    },
    edit() {
      this.$router.push({
        path: "addfile",
        query: { id: this.$route.query.id },
      });
    },
    handleShow(name) {
      this.showCalendar = true;
      this.selectKey = name;
    },
    onConfirm(date) {
      const dateTime = formatDate(date);
      this.form[this.selectKey] = getDate(dateTime);
      this.showCalendar = false;
    },
    handleDelete(item) {
      Dialog.confirm({
        title: "询问",
        message: "确定要删除该附件吗?",
      })
        .then(() => {
          // on confirm
          let _this = this;
          _this.$axios
            .post("/EquEquipment/DeleteEquipmentSafeFileFile", {
              ID: item.ID,
              SEQ: item.SEQ,
            })
            .then((res) => {
              _this.$toast.success("删除成功！");
              _this.$refs.eaglePageList.search();
            });
        })
        .catch(() => {
          // on cancel
        });
    },
    handleConfirm() {
      //this.form.equipmentCode = this.$route.query.equipmentCode
      let _this = this;
      _this.$axios
        .post("/EquEquipment/EditCheckEquipmenSafeFile", _this.form)
        .then((res) => {
          _this.$toast.success("编辑成功！");
          _this.$refs.eaglePageList.search();
        });
    },
    getFile() {
      this.$router.push({
        path: "/Equipment/SafetyFile",
        query: { equipmentCode: equipmentCode },
      });
    },
    // 详情
    goDetail(ChemCode) {
      this.$router.push({
        path: "/Chemical/Detail",
        query: { ChemCode: ChemCode },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.van-cell {
  padding: 0 0;
}
.all_dep {
  background-color: #ffffff;
}
.warn_item {
  /*margin-bottom: 10px;*/
  padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: -4px;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
